﻿
/*
*   描述：主控信道上行行占用率排行显示
*   编写：qfkong
*   时间：2011.06.21 14:00
*/


var baseData; //基本数据集
var freshTime = 60000; //数据更新时间，默认为30秒钟
var topNumber = 20; //排行数目，默认为20
var isShowvalue = false; //是否显示统计图上的数据，默认为不显示

$(function (e) {
    GetData();
});

function GetData() {
    $.ajax({
        type: "GET",
        url: 'TBSChannel.ashx',
        data: 'uplink=&top=' + topNumber,
        cache:false,
        success: function (dt) {
            if (dt && dt.rows && dt.rows.length > 0) {
                baseData = dt;
                CreateFusionLineChart(baseData);
            }
        },
        error: function (e) {

        }
    });
}
/*创建统计曲线*/
function CreateFusionLineChart(dt) {
    var myChart = new FusionCharts("../JS/FusionCharts/swf/ScrollColumn2D.swf", "ChartId", $(document).width(), "300", "0", "0");
    myChart.setDataXML(setXML(dt));
    myChart.render("chartLine");
}
/*组装 XML*/
function setXML(dt) {
    var xmlStrCat = '<categories>';
    var xmlStr = '<dataset>';
    for (var i = 0, length = dt.rows.length; i < length; i++) {
        xmlStr += ' <set label="' + dt.rows[i]['CHINA_NAME'] + '" value="' + dt.rows[i]['MCCH_UPLINK_USAGE'] + '"';
        xmlStr += ' link="javascript:openTBSLink(\'' + dt.rows[i]['NE_ID'] + '\');"  tooltext="基站：' + dt.rows[i]['CHINA_NAME'] + '{br}时间：' + dt.rows[i]['REPORT_TIMESTAMP'] + '{br}占用率：' + dt.rows[i]['MCCH_UPLINK_USAGE'] + '%"/> ';
        xmlStrCat += ' <category label="' + dt.rows[i]['CHINA_NAME'] + '" />';
    }

    xmlStr += '</dataset>';
    xmlStr += ' <styles>';
    xmlStr += ' <definition>';
    xmlStr += '        <style name="myCaptionFont" type="font" font="Arial" size="14" color="666666" bold="1"/>';
    xmlStr += '     </definition>';
    xmlStr += '     <application>';
    xmlStr += '        <apply toObject="Caption" styles="myCaptionFont" />';
    xmlStr += '     </application>';
    xmlStr += '   </styles>';
    xmlStr += '  </chart>';
    xmlStrCat += ' </categories>';

    var xmlStrTmp = '<chart caption="主控信道上行占用率排行" canvasPadding="5" captionPadding="2" chartBottomMargin="10" animation="0" ';
    xmlStrTmp += '  showLegend="0"  showAboutMenuItem="1" showValues="' + (isShowvalue || 0) + '" bgColor="#E4F0FC" canvasBgAlpha="100" canvasBorderThickness="0" chartTopMargin ="5" chartLeftMargin="10" ';
    xmlStrTmp += ' >';

    return xmlStrTmp + xmlStrCat + xmlStr;
}

function openTBSLink(neid) {
    var url = 'TBSChannelLink.htm?neid=' + neid+'&type=up';
    window.open(url, 'tbsChannelLink', 'directorys=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width=900,height=420,left=20,top=10');
}


var freshInterval = setInterval(GetData, freshTime); //30秒更新一次数据

/*更新统计图*/
function updateChart() {
    var txtTop = $('#txtTOP').val();
    try {
        if (parseInt(txtTop) < 0) {
            alert('TOP数目不能小于0!');
            $('#txtTOP').focus();
            return false;
        }
    } catch (e) {
        alert('输入的只能为整数!');
        $('#txtTOP').focus();
        return false;
    }
    topNumber = txtTop;
    isShowvalue = $('#check_show')[0].checked ? 1 : 0;

    GetData();

    freshTime = parseInt($('#updateTime :selected').val());
    clearInterval(freshInterval);
    freshInterval = setInterval(GetData, freshTime); //30秒更新一次数据    
}